<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no" />
    <title>清人数 V2.0</title>
    <link rel="stylesheet" href="css/iconfont.css">
    <link rel="stylesheet" href="css/bootstrap.css">
    <!--    <script src="js/jquery-1.12.4.min.js"></script>-->
    <!--    <script src="js/index.js"></script>-->
    <script src="js/vue.min.js"></script>
    <style>
        body {
            padding: 15px;
        }
    </style>
</head>

<body>
    <div class="panel panel-primary" id="app">
        <h1 style="text-align: center">{{time | format('yyyy-MM-dd hh:mm:ss')}}</h1>
        <div class="panel-heading" style="position: relative;">
            <h3 class="panel-title">查询</h3>
            <i class="iconfont icon-chaxun" style="position: absolute; left: 50px; top: 9px; cursor: pointer;"></i>
        </div>
        <div class="query">
            <div class="input-group-addon" style="cursor: pointer;" @click="QueryStudent">查询</div>
            <input type="text" class="form-control" placeholder="请输入已交的学号" style="cursor: pointer;" v-model="ipt" v-focus @keyup.enter="QueryStudent" @keyup.delete="clearData">
            <div class="input-group-addon" style="cursor: pointer;" @click="clearData">清除</div>
        </div>
        <div id="ok">
            <div class="panel-body form-inline">已交List {{yes.length}}人</div>
            <!-- 已交列表列表 -->
            <table class="table table-bordered table-hover">
                <thead>
                    <tr>
                        <td>学号</td>
                        <td>姓名</td>
                    </tr>
                </thead>
                <tbody id="yesList">
                    <tr :key="item.id" v-for="item in yes">
                        <td>{{item.id}}</td>
                        <td @click="changeNoData(item)">{{item.name}}</td>
                    </tr>
                </tbody>
            </table>
            <p style="color: red;" id="okPerson"></p>
        </div>
        <hr style="color: red;">
        <div id="no">
            <div class="panel-body form-inline">未交List {{no.length}}人</div>
            <!-- 已交列表列表 -->
            <table class="table table-bordered table-hover">
                <thead>
                    <tr>
                        <td>学号</td>
                        <td>姓名</td>
                    </tr>
                </thead>
                <tbody id="noList">
                    <tr :key="item.id" v-for="item in no" v-show="item.status == false">
                        <td>{{item.id}}</td>
                        <td @click="changeYesData(item)">{{item.name}}</td>
                    </tr>
                </tbody>
            </table>
            <p style="color: red;" id="noPerson"></p>
        </div>
    </div>
    <script src="js/time.js"></script>
    <script>
        Vue.directive('focus', {
            inserted(el) {
                el.focus();
            }
        })
        Vue.filter('format', (val, reg) => {
            return dateFormat(val, reg);
        })
        let vm = new Vue({
            el: '#app',
            data: {
                Student: [],
                yes: [],
                no: [],
                ipt: '',
                StudentID: [],
                time: ''
            },
            methods: {
                QueryStudent() {
                    if (this.ipt.trim() != '') {
                        let str = this.ipt.split(',');
                        this.StudentID = str;
                        // 已交
                        this.StudentID.forEach((val) => {
                            this.Student.some((item) => {
                                if (item.id == val) {
                                    item.status = true;
                                    return true;
                                }
                            })
                        });
                        // 已交
                        this.yes = this.Student.filter((item) => {
                            return item.status;
                        });
                        // 未交
                        this.no = this.Student.filter((item) => {
                            return !item.status;
                        });
                        this.ipt = '';
                    }
                },
                clearData() {
                    this.yes = [];
                    this.no = [];
                },
                changeYesData(item) {
                    item.status = true;
                    this.yes.push(item);
                },
                changeNoData(val) {
                    val.status = false;
                    this.yes = this.yes.filter((item) => {
                        return item.status != false;
                    });
                    this.no.push(val);
                }
            },

            mounted() {
                let data = [{
                    id: 30,
                    name: '吴杨',
                    status: false
                }, {
                    id: 31,
                    name: '吴志浩',
                    status: false
                }, {
                    id: 32,
                    name: '丁洪宇',
                    status: false
                }, {
                    id: 33,
                    name: '佘文辉',
                    status: false
                }, {
                    id: 35,
                    name: '黄柄权',
                    status: false
                }, {
                    id: 36,
                    name: '马锐',
                    status: false
                }, {
                    id: 37,
                    name: '喻文希',
                    status: false
                }, {
                    id: 38,
                    name: '兰天盟',
                    status: false
                }, {
                    id: 39,
                    name: '徐心念',
                    status: false
                }, {
                    id: 40,
                    name: '夏思妮',
                    status: false
                }, {
                    id: 41,
                    name: '胡文杰',
                    status: false
                }, {
                    id: 42,
                    name: '毛徐东',
                    status: false
                }, {
                    id: 43,
                    name: '李梦玲',
                    status: false
                }, {
                    id: 44,
                    name: '邓彧',
                    status: false
                }, {
                    id: 45,
                    name: '李博',
                    status: false
                }, {
                    id: 46,
                    name: '张瑶',
                    status: false
                }, {
                    id: 47,
                    name: '杨文杰',
                    status: false
                }, {
                    id: 48,
                    name: '廖朋林',
                    status: false
                }, {
                    id: 49,
                    name: '方潇',
                    status: false
                }, {
                    id: 51,
                    name: '万俊辉',
                    status: false
                }, {
                    id: 52,
                    name: '陈梓琪',
                    status: false
                }, {
                    id: 53,
                    name: '吴婉',
                    status: false
                }, {
                    id: 54,
                    name: '胡梓航',
                    status: false
                }, {
                    id: 55,
                    name: '刘文谦',
                    status: false
                }, {
                    id: 56,
                    name: '李飞',
                    status: false
                }, {
                    id: 57,
                    name: '乐涛',
                    status: false
                }, {
                    id: 58,
                    name: '李春雨',
                    status: false
                }, {
                    id: 19,
                    name: '徐凯',
                    status: false
                }];
                this.Student = data;
                this.time = new Date();
                setInterval(() => {
                    this.time = new Date();
                }, 1000)
            }

        });
    </script>
</body>

</html>